import { Router } from 'express';
import { FloorController } from '../../admin/controllers/floorController';
import { authenticate, authorize } from '../../middleware/auth';
import { ALL_PERMISSIONS } from '../../constants/permissions';
import { uploadFloorPlan } from '../../middleware/upload';

// 文件级注释：楼层管理路由，需管理员认证与权限
const router = Router();
const controller = new FloorController();

// 认证
router.use(authenticate);

// 列表与详情
router.get('/', authorize([ALL_PERMISSIONS.FLOOR_LIST, ALL_PERMISSIONS.FLOOR_READ]), controller.list.bind(controller));
router.get('/:id', authorize([ALL_PERMISSIONS.FLOOR_READ]), controller.detail.bind(controller));

// 创建与更新
router.post('/', authorize([ALL_PERMISSIONS.FLOOR_CREATE]), uploadFloorPlan, controller.create.bind(controller));
router.put('/:id', authorize([ALL_PERMISSIONS.FLOOR_UPDATE]), uploadFloorPlan, controller.update.bind(controller));

// 删除
router.delete('/:id', authorize([ALL_PERMISSIONS.FLOOR_DELETE]), controller.remove.bind(controller));

// 启用/禁用
router.post('/:id/enable', authorize([ALL_PERMISSIONS.FLOOR_ENABLE]), controller.enable.bind(controller));
router.post('/:id/disable', authorize([ALL_PERMISSIONS.FLOOR_DISABLE]), controller.disable.bind(controller));

// 平面图上传
router.post('/:id/floor-plan', authorize([ALL_PERMISSIONS.FLOOR_UPDATE]), uploadFloorPlan, controller.uploadFloorPlan.bind(controller));

export default router;


